﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using STT.Business;
using STT.Entities;
using STT.Layer.Connection;
using System.Data;
using System.IO;
namespace STT.Report
{
    public partial class ViewBangDiem : System.Web.UI.Page
    {
         
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        void ThongBao(string Loi)
        {
            ScriptManager.RegisterClientScriptBlock(this, GetType(), "Thông báo!", "<script>alert('" + Loi + "')</script>", false);
        }
        protected void ddkh_SelectedIndexChanged(object sender, EventArgs e)
        {

            ddlop.DataSource = BTbLop.SelectTuKhoaHoc(int.Parse(ddkh.SelectedValue));
            ddlop.DataTextField = "TenLop";
            ddlop.DataValueField = "MaLop";
            ddlop.DataBind();

        }
        protected void lbXuatDuLieu_Click1(object sender, EventArgs e)
        {
            try
            {
                DataTable dt = BTbBangDiem.SelectAll_Xuat_Diem(ddlop.SelectedValue, int.Parse(ddkh.SelectedValue));
                gvDiem.DataSource = dt;
                gvDiem.DataBind();
                Response.Clear();
                Response.Buffer = true;
              
              
              
                Response.AddHeader("content-disposition",
                 "attachment;filename=" + ddlop.SelectedItem.Text + ".xls");
                Response.Charset = "";
                Response.ContentType = "application/vnd.ms-excel";
                StringWriter sw = new StringWriter();
                HtmlTextWriter hw = new HtmlTextWriter(sw);
                // Bỏ phân trang - Nếu chỉ muỗn Export Trang hiện hành thì chọn =true
                gvDiem.AllowPaging = false;
                gvDiem.DataBind();
                gvDiem.RenderControl(hw);
                //Thay đổi Style
                string style = @"";
                Response.Write(style);
                Response.Output.Write(sw.ToString());
                Response.Flush();
                Response.End();
            }
            catch
            {
                ThongBao("Bạn phải chọn đủ dữ liệu cần thiết khi xuất File !");
            }

        }
    }
}